package ServerListener;

import java.net.Socket;

import Message.MessageTypes;
import Message.XMLmessage;
import Player.mPlayer;

public class SocketIsOpenListener extends Thread {
	private static volatile boolean allreadyRunning = false;
	private Socket socket = ServerListener.Socket;
	private mPlayer player = ServerListener.Player;
	
	SocketIsOpenListener() {
		socket = ServerListener.Socket;
		player = ServerListener.Player;
	}
	
 public void run() {
	 while (allreadyRunning) {
		 try {
			Thread.sleep(4000);
		
		 XMLmessage msgPing = new XMLmessage(MessageTypes.Ping, player);
		 msgPing.send(socket);
		 } catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	 }
 }
 
 @Override
 public void start() {
	 if (!allreadyRunning) {
		 super.start();
		 allreadyRunning = true;
	 }
 }
}
